package com.peace.hospital.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;

import com.peace.hospital.entity.drugstorage.dto.ModpriceDto;
import com.peace.hospital.entity.drugstorage.dto.ModpriceDto2;
import com.peace.hospital.service.drugstorage.IModpriceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * <p>
 * 调价表 前端控制器
 * </p>
 *
 * @author xie
 * @since 2019-11-23
 */
@RestController
@RequestMapping("/modprices")
public class ModpriceController {
    @Autowired
    private IModpriceService iModpriceService;

    //添加调价信息
    @RequestMapping(value = "/insert", method = {RequestMethod.POST})

    public String addModprice(@RequestBody ModpriceDto modpriceDto ){

        System.out.println(modpriceDto);
        boolean bol= iModpriceService.InsertModprice(modpriceDto);
        if(bol==true){
            return JSON.toJSONString( "添加成功");
        }
            return JSON.toJSONString("添加失败");

   }


  //查询调价信息
  @RequestMapping(value = "/select", method = {RequestMethod.GET})
  public  String selectModprice(@RequestBody Integer drugid){
      System.out.println(drugid);
      List<ModpriceDto2> list= iModpriceService.selectModprice(drugid);
      if(null!=list){
          for (ModpriceDto2 modpriceDto2 : list) {
              System.out.println(modpriceDto2);
          }

          return  JSON.toJSONStringWithDateFormat(list ,"YYYY-MM-dd", SerializerFeature.WriteDateUseDateFormat);
      }
          return  null;

  }

}
